angular.module('myApp')
.controller('UploadCtrl', ['$scope', function($scope) {
  $scope.message = 'Hello, AngularJS!';
  $scope.handleChange = (files) => {
    console.log(files,22);
  }
  $scope.handleRemove = (files) => {
    console.log(files,11, $scope);
  }
}])
.directive('elUpload', ['$http', '$parse', '$timeout', elUpload])
.filter('fileSize', function() {
  return function(bytes, precision = 2) {
    // 处理无效输入
    if (typeof bytes !== 'number' || isNaN(bytes)) return '0 B';
    if (bytes === 0) return '0 B';

    // 单位换算
    const units = ['B', 'KB', 'MB', 'GB', 'TB'];
    const unitIndex = Math.floor(Math.log(bytes) / Math.log(1024));
    const size = bytes / Math.pow(1024, unitIndex);

    // 结果格式化
    return `${size.toFixed(precision)} ${units[unitIndex]}`;
  };
});